package com.zz.excel.service;

import com.zz.excel.anno.ImportExcelMark;
import com.zz.excel.dto.ExcelTwoDto;
import com.zz.excel.exportExcelModel.ExcelTwo;
import com.zz.excel.mapper.ExcelDemoOneMapper;
import com.zz.excel.utils.CloneUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ExcelServiceImpl implements ExcelService {

    @Autowired
    ExcelDemoOneMapper excelDemoOneMapper; //excelDemoOneMapper是一个代理对象，而不是真实对象

    @Override
    //@ImportExcelMark
    public int batchInsert(List<ExcelTwo> excelTwoList) {
        //情况2：如果Service接口方法接收的是ExcelTwo实体类，Mapper接口方法接收的都是ExcelTwoDto实体类
        List<ExcelTwoDto> excelTwoDtos = CloneUtils.batchClone(excelTwoList, ExcelTwoDto.class);
        return excelDemoOneMapper.batchDtoInsert(excelTwoDtos);

        //情况1：如果Service接口方法与Mapper接口方法接收的都是ExcelTwo实体类
        //return excelDemoOneMapper.batchInsert(excelTwoList);
    }

    @Override
    @ImportExcelMark
    public int batchDtoInsert(List<ExcelTwoDto> excelTwoDtos) {
        //情况3：如果Service接口方法与Mapper接口方法接收的都是ExcelTwoDto实体类
        return excelDemoOneMapper.batchDtoInsert(excelTwoDtos);
    }
}
